﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Ewts.Storage
{
    public partial class CascView : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string no = txtNo.Text.Trim();
            if (no != "")
            {
                DataTable dt = new DataTable();
                //dt = new DataLib.BLL.LoadNum().GetTreeVieww(no,);

                //if (dt != null && dt.Rows.Count > 0)
                //{
                //    //根节点 Load
                //    DataRow[] drs = dt.Select("parmentid='0'");
                //    foreach (DataRow dr in drs)
                //    {
                //        TreeNode tn = new TreeNode();
                //        tn.Text = dr["selfno"].ToString();
                //        tn.Value = dr["selfno"].ToString();
                //        tn.Expanded = false;
                //        bindTree(dt, tn);
                //        TreeView1.Nodes.Add(tn);
                //    }
                //}

            
            }
        }


   
        /// <summary>
        /// 子节点循环
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="tn"></param>
        public void bindTree(DataTable dt, TreeNode tn)
        {
          
                DataRow [] cdr = dt.Select("parmentid='" + tn.Value +"'");
                TreeNode cnode = new TreeNode();
                for (int i = 0; i < cdr.Length; i++)
                {
                    TreeNode childnode = new TreeNode();
                    childnode.Value = cdr[i]["selfno"].ToString(); 
                    childnode.Text = cdr[i]["selfno"].ToString();
                    bindTree(dt, childnode);
                    tn.ChildNodes.Add(childnode);
                }
             
     
       }
    }
}